/***************************************************************************
 *   Copyright (C) 2007 by Ziman & Xloverin                                *
 *   ziman@centrum.sk, xloverin@gmail.com                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef TAGCACHE_H
#define TAGCACHE_H

#include <QString>
#include <QRegExp>
#include <QList>
#include "line.h"

/**
 * Cachuje regexpy pre regularne vyrazy natiahnute z databazy.
 * @author Ziman & Xloverin <ziman@centrum.sk, xloverin@gmail.com>
 */
class TagCache
{
	/// Zaznam o tagu.
	struct Entry {
		/// Prislusny tag.
		Line::Tag tag;
		/// Regex, ktory musi lajna splnat, aby jej mohol byt prideleny tento tag. (Nutna, nie postacujuca podmienka).
		QRegExp re;
	};
	
	typedef	QList<Entry> Entries;
	
	/// Zoznam zaznamov o tagoch nacitany z databazy.
	Entries entries;
	
	/// Zoznamy zaznamov rozdelene podla typu. (Zaznamenavaju sa indexy do zoznamu vsetkych zaznamov).
	QList<int> types[LINE_TYPE_COUNT];
	
	/// Otestuje, ci mozu (potencionalne) sediet zadane parametre dokopy.
	bool tagMayMatch(const QString &plain, Line::Type typeHint, const Entry &e, bool BEL);
	
	public:
		
		/**
		 * Dost komplexna funkcia -- pokusi sa otagovat lajnu.
		 * @param plain Plaintextova lajna.
		 * @param typeHint Ak je typeHint == Unknown, potom sa snazi urcit typ lajny
		 * 	z udajov v databaze. Inak vybera iba z typov rovnych typeHintu.
		 * @param BEL Vravi, ci riadok obsahoval ASCII BEL.
		 * @return Tag lajny.
		 */
		Line::Tag getTag(const QString &plain, Line::Type typeHint, bool BEL);
		
		TagCache();
		~TagCache();

};

#endif
